package com.douwong.student.task;

import android.os.AsyncTask;
import android.util.Log;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.douwong.student.contant.NetConfig;
import com.douwong.student.interfaces.DetailNotify;
import com.douwong.student.model.HallTestData;
import com.douwong.student.model.StatusCode;
import com.douwong.student.utils.NetUtils;

import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;

public class ClassExamDetailTask extends AsyncTask<String, Integer, Integer>{

	public static int REQUEST_OK = 1;
	private int ERROR=-1;
	private DetailNotify detailListener;
	private String content;
	@Override
	protected Integer doInBackground(String... params) {
		String response = null;
		int stateCode = REQUEST_OK;
		List<BasicNameValuePair> arrayParams = new ArrayList<BasicNameValuePair>();
		try {
				arrayParams.add(new BasicNameValuePair("lessonExamineId", params[0]));
				response = NetUtils.httpGet(NetConfig.CLASS_EXAM_DETAIL,
						arrayParams);
				StatusCode<HallTestData> sc = (StatusCode<HallTestData>) JSON
						.parseObject(response,
								new TypeReference<StatusCode<HallTestData>>() {
								});
				if (sc != null && sc.isFlag()) {
					content=response;
				}else{
					stateCode=ERROR;
				}
				Log.e("content", content + "");
		} catch (Exception e) {
			e.printStackTrace();
			stateCode=ERROR;
		}

		return stateCode;
	}
	@Override
	protected void onPostExecute(Integer result) {
		super.onPostExecute(result);
		detailListener.notify(result, content);
	}

	public void setDetailListener(DetailNotify detailListener) {
		this.detailListener = detailListener;
	}
	
}
